package com.barras;

import java.util.Random;

import org.achartengine.ChartFactory;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.model.CategorySeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer.Orientation;
import org.achartengine.renderer.XYSeriesRenderer;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint.Align;

public class classBarra 
{
	public XYMultipleSeriesDataset dataset = null;
	public XYMultipleSeriesRenderer mRenderer = null;
	
	public Intent getIntent (Context context)
	{
		int [] y = {124, 135, 200, 455, 121, 233};
		int [] y1 = {224, 235, 110, 355, 221, 133};
		
		CategorySeries series = new CategorySeries("Demo de Barras");
		for (int i=0;i<y.length;i++){
			series.add("Barra" + (i+1), y[i]);			
		}
		
		CategorySeries series2 = new CategorySeries("Demo de Barras 2");
		for (int i=0;i<y1.length;i++){
			series2.add("Barra" + (i+1), y1[i]);			
		}
		
		dataset = new XYMultipleSeriesDataset();
		dataset.addSeries(series.toXYSeries());
		dataset.addSeries(series2.toXYSeries());
		//#####################################
		
		//MODIFCAR LOS DATOS DE UNA BARRA
		XYSeriesRenderer renderer = new XYSeriesRenderer();
		XYSeriesRenderer renderer2 = new XYSeriesRenderer();
		
		//Valores
		renderer.setDisplayChartValues(true); //Mostrar
		renderer.setChartValuesSpacing(60); //Espacio entre el punto y el valor
		renderer.setChartValuesTextAlign(Align.RIGHT); //centrado
		renderer.setChartValuesTextSize(35); //tamano
		int [] n = this.dameAleatorios();
		renderer.setColor(Color.argb(255,n[1],n[2],n[3]));
		
		renderer2.setDisplayChartValues(true); //Mostrar
		renderer2.setChartValuesSpacing(60); //Espacio entre el punto y el valor
		renderer2.setChartValuesTextAlign(Align.RIGHT); //centrado
		renderer2.setChartValuesTextSize(35); //tamano
		n= this.dameAleatorios();
		renderer2.setColor(Color.argb(255,n[1],n[2],n[3])); 

		//MODIFICAR CARACTERISTICAS DE TODO EL CHART
		mRenderer = new XYMultipleSeriesRenderer();
				
		mRenderer.addSeriesRenderer(renderer);
		mRenderer.addSeriesRenderer(renderer2);
		mRenderer.setBarSpacing(1);
				
		//Titulo del reportes
		mRenderer.setChartTitle("Reporte de Ventas");
		mRenderer.setChartTitleTextSize(30);
		mRenderer.setLabelsColor(Color.WHITE); //Esto es para todos los labels
		
		//Orientacion del eje x
		mRenderer.setOrientation(Orientation.VERTICAL);
		
		//Cuadricula
		mRenderer.setShowGrid(true);
		mRenderer.setGridColor(Color.WHITE);
		mRenderer.setXLabels(10); //Cantidad de lineas
		mRenderer.setYLabels(10); //Cantidad de lineas
		
		//Ejes X,Y
		mRenderer.setPanEnabled(true,true); //Habilitar movimiento {x,y}
		//mRenderer.setPanLimits(new double[] {0,0,0,0});
		
		//Cuadrar la grafica
		mRenderer.setMargins(new int[] {20, 100, 30, 150}); //{derecha, arriba, izquierda, abajo}
		
		//Leyenda de la grafica
		mRenderer.setLegendTextSize(25);
		mRenderer.setLegendHeight(70);
		
		mRenderer.setZoomRate(1.1f);
		mRenderer.setZoomButtonsVisible(true);
		
		//Centrar las barras
		mRenderer.setXAxisMin(0);
		mRenderer.setYAxisMin(0);
		mRenderer.setXAxisMax(6+1);
		mRenderer.setYAxisMax(455+100);
		
		mRenderer.setXTitle("EJE X");
		mRenderer.setYTitle("EJE Y");
		mRenderer.setAxisTitleTextSize(25);
		
		Intent intent = ChartFactory.getBarChartIntent(context, dataset, mRenderer, Type.STACKED);
		return intent;
	}
	
	public int[] dameAleatorios(){
		int [] numeros = new int[4];
		
		for (int i=0;i<4;i++)
			numeros[i] = (int)(Math.random()*255);
		
		return numeros;
	}
}
